<?php
/**
 * Admin路由器
 * 处理admin目录下的路由请求
 */

// 获取请求路径
$requestUri = $_SERVER['REQUEST_URI'];
$requestPath = parse_url($requestUri, PHP_URL_PATH);

// 移除前缀 /admin/
$path = substr($requestPath, 7); // 移除 "/admin/"
if (empty($path)) {
    $path = 'index.php';
}

// 根据路径路由到对应文件
switch ($path) {
    case '':
    case '/':
    case 'index':
    case 'index.php':
        // 重定向到dashboard页面
        header('Location: /admin/dashboard');
        exit;
        break;

    case 'dashboard':
    case 'dashboard.php':
        require_once 'dashboard.php';
        break;

    case 'login':
    case 'login.php':
        require_once 'login.php';
        break;

    case 'categories':
    case 'categories.php':
        require_once 'categories.php';
        break;

    case 'navigations':
    case 'navigations.php':
        require_once 'navigations.php';
        break;

    case 'settings':
    case 'settings.php':
        require_once 'settings.php';
        break;

    case 'tags':
    case 'tags.php':
        require_once 'tags.php';
        break;

    default:
        // 默认返回404
        http_response_code(404);
        echo '<h1>404 - Page Not Found</h1>';
        echo '<p>The requested admin page could not be found.</p>';
        break;
}
?>